Sort the array in ascending order and find the maximum element